#@adminLayout()

#define content()
#if(notice)
<script>
  alert("#(notice)");
</script>
#end
<div class="am-cf am-padding am-padding-bottom-0">
  <div class="am-fl am-cf">
    <strong class="am-text-primary am-text-lg">[#(group.name)] 计划明细</strong>
  </div>
  <div style="float: right">
    <button class="am-btn am-btn-success am-btn-xs" onclick="window.location.href='/admin/template/add?gid=#(group.id)'"><span class="am-icon-plus"></span>
      添加计划
    </button>
  </div>
</div>
<hr>
<div class="am-g">
  <div class="am-u-sm-12">
    <table class="am-table am-table-striped am-table-hover table-main">
      <thead>
      <tr>
        <th class="table-id">ID</th>
        <th class="table-title">公司名称</th>
        <th class="table-type">车牌号</th>
        <th class="table-author am-hide-sm-only">入库位置</th>
        <th class="table-author am-hide-sm-only">入库时间</th>
        <th class="table-set">操作</th>
      </tr>
      </thead>
      <tbody>
      #for(template : templateList)
      <tr>
        <td>#(for.count)</td>
        <td>#(template.company)</td>
        <td>#(template.van)</td>
        <td class="am-hide-sm-only">#(template.position)</td>
        <td class="am-hide-sm-only">#(tools.formatTime(template.hour, template.minute))</td>
        <td>
          <div class="am-btn-toolbar">
            <button type="button" class="am-btn am-btn-primary am-btn-xs" onclick="edit('#(template.id)');"><span
                class="am-icon-edit"></span>
              修改</button>
            <button type="button" class="am-btn am-btn-danger am-btn-xs" onclick="del('#(template.id)', '#(group.id)');"><span
                class="am-icon-remove"></span>
              删除</button>
          </div>
        </td>
      </tr>
      #else
      <tr>
        <td colspan="6" style="text-align: center">暂无记录</td>
      </tr>
      #end
      </tbody>
    </table>
  </div>
</div>
<hr>
<form class="am-form" id="form" action="/admin/template/activeTemplate" method="post">
  <input type="hidden" name="gid" value="#(group.id)">
  <div class="am-cf am-padding am-padding-bottom-0">
    <div class="am-fl am-cf">
      <input type="text" name="dateStr" class="am-form-field" placeholder="选择计划生效日期" data-am-datepicker readonly required />
    </div>
    <div>
      <button type="button" class="am-btn am-btn-primary" onclick="activeTemplate();"><span class="am-icon-play"></span>
        启用计划
      </button>
    </div>
  </div>
</form>

<script type="text/javascript">
  function edit(id) {
    var url = "/admin/template/edit?id=" + id;
    window.location.href=url;
  }

  function del(id, gid) {
    if(confirm("确认执行删除操作?")) {
      var url = "/admin/template/delete?id=" + id + "&gid=" + gid;
      window.location.href=url;
    }
  }

  function activeTemplate() {
    var date = $("input[name='dateStr']").val();
    if(date == "") {
      alert("请选择计划启用时间");
      return;
    }
    if (confirm("确认计划在 [" + date + "] 启用?")) {
      $("#form").submit();
    }
  }
</script>
#end